import {
    createRouter,
    createWebHashHistory
} from 'vue-router'
import loginView from '../views/login.vue'
import startView from '../views/start.vue'
import bigcontrollerView from "../views/controller/bigcontroller.vue"
import smallcontrollerView from "../views/controller/smallcontroller.vue"
import gameView from "../views/game/index.vue"
import process1View from "../views/processdetail/process1.vue"
import mineView from "../views/setting/mine.vue"
import AchievementsView from "../views/setting/Achievements.vue"
import process5View from "../views/processdetail/process5.vue"
import gametopicView from "../views/game/gametopic.vue"
import process2View from "../views/processdetail/process2.vue"
import prewardView from "../views/game/reward.vue"
import unrewardView from "../views/game/unreward.vue"
import usmallrewardView from "../views/game/smallreward.vue"
import gongguView from "../views/processdetail/gonggu.vue"
import dataview from "../views/setting/data.vue"
import smallerrorView from '../views/game/smallerror.vue'

import {
    useAuthStore
} from '../store/index';
import {
    useRouter
} from 'vue-router'

// const Store = useAuthStore();
const router = createRouter({
    history: createWebHashHistory(
        import.meta.env.BASE_URL),
    routes: [{
            path: '/',
            children: [{
                path: '',
                name: 'login',
                component: loginView,
                meta: {
                    requiresAuth: true
                },
            },  {
                path: 'start',
                name: 'start',
                component: startView,
                meta: {
                    requiresAuth: true
                },
            }]
        },{
            path: '/controller',
            children: [{
                path: '/big',
                name: 'bigcontroller',
                component: bigcontrollerView,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/small',
                name: 'smallcontroller',
                component: smallcontrollerView,
                meta: {
                    requiresAuth: true
                },
            }]
        },{
            path:"/game",
            name: 'game',
            component: gameView,
        },{
            path:"/smallreward",
            name: 'smallreward',
            component: usmallrewardView,
        },{
            path:"/preward",
            name: 'preward',
            component: prewardView,
        },{
            path:"/unreward",
            name: 'unreward',
            component: unrewardView,
        },{
            path:"/smallerror",
            name: 'smallerror',
            component: smallerrorView,
        },{
            path:"/gametopic",
            name: 'gametopic',
            component: gametopicView,
        },{
            path:"/process",
            children: [{
                path: '/detail1',
                name: 'processdetail1',
                component: process1View,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/detail2',
                name: 'processdetail2',
                component: process2View,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/detail5',
                name: 'processdetail5',
                component: process5View,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/gonggu',
                name: 'gonggu',
                component: gongguView,
                meta: {
                    requiresAuth: true
                },
            }]
        },{
            path:"/setting",
            children: [{
                path: '/mine',
                name: 'mine',
                component: mineView,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/Achievements',
                name: 'Achievements',
                component: AchievementsView,
                meta: {
                    requiresAuth: true
                },
            },{
                path: '/data',
                name: 'data',
                component: dataview,
                meta: {
                    requiresAuth: true
                },
            }]
        }

    ]
})


router.beforeEach((to, from, next) => {
    const routerx = useRouter()
    if (to.path == "/") {
        useAuthStore().setpagetrue();
        useAuthStore().setpagetitle("阳哥电源");
    }

    // console.log(store.pagestate)
    // console.log('当前路由器实例:', currentRouter)
    next();
})

export default router